<template>
  <div>
    <van-form @submit="onSubmit">
      <van-nav-bar title="面经登录" />
      <van-field
        v-model="username"
        name="username"
        label="用户名"
        placeholder="用户名"
        :rules="[{ required: true, message: '请填写用户名' }]"
      />
      <van-field
        v-model="password"
        type="password"
        name="password"
        label="密码"
        placeholder="密码"
        :rules="[{ required: true, message: '请填写密码' }]"
      />
      <div style="margin: 16px">
        <van-button block type="info" native-type="submit">提交</van-button>
      </div>
    </van-form>
   <div style="text-align: right; margin-right: 20px;"> 
    <router-link to="/Register" style="">注册账号</router-link>
    </div>
  </div>
</template>
<script>
import {loginAPI} from '../api/user'
import request from '../utils/request'
import { setToken } from '@/utils/storage'
// import Toast from 'vant';
export default {
  data () {
    return {
      username: '11223344',
      password: '11223344',
    };
  },
  methods: {
  async  onSubmit (values) {
      console.log('submit', values);
       console.log('submit',values );//values{用户名: '18672776151', 密码: '18672776151'}
  //  const res= await  request.post('/user/login',values)
   const res= await loginAPI(values)
   console.log(res)
      this.$toast('登录成功')
      setToken(res.data.token)
      this.$router.push('/')//登录成功之后挑转
    },
  },
};
</script>
<style lang='less'  scoped>
.van-button {
  background-color: orangered;
  color: #fff;
  border: none;
}
</style>
